/**
 *
 * @authors 前端小灰狼
 * @date    2020-12-10 16:48:28
 * @version v1.0
 * @description the core js of todolist project
 *
 * ━━━━━━神兽出没━━━━━━
 * 　　   ┏┓　 ┏┓
 * 　┏━━━━┛┻━━━┛┻━━━┓
 * 　┃              ┃
 * 　┃       ━　    ┃
 * 　┃　  ┳┛ 　┗┳   ┃
 * 　┃              ┃
 * 　┃       ┻　    ┃
 * 　┃              ┃
 * 　┗━━━┓      ┏━━━┛ Code is far away from bugs with the animal protecting.
 *       ┃      ┃     神兽保佑,代码无bug。
 *       ┃      ┃
 *       ┃      ┗━━━┓
 *       ┃      　　┣┓
 *       ┃      　　┏┛
 *       ┗━┓┓┏━━┳┓┏━┛
 *     　  ┃┫┫　┃┫┫
 *     　  ┗┻┛　┗┻┛
 *
 * ━━━━━━感觉萌萌哒━━━━━━
 */

// 请根据考试说明文档中列出的需求进行作答
// 预祝各位顺利通过本次考试，see you next week！
// ...
var title = document.querySelector('#title');
var todolist = document.querySelector('#todolist');
title.onkeydown = function(){
    var e = window.event;
    var keycode = e.keyCode || e.which;
    if(keycode === 13){
        var li = document.createElement('li')
        todolist.appendChild(li)
        var checkbox = document.createElement('input')
        checkbox.type = 'checkbox'
        li.appendChild(checkbox)
        var p = document.createElement('p')
        p.innerText = this.value;
        li.appendChild(p)
        var a = document.createElement('a')
        a.setAttribute('href', 'javascript:;')
        a.innerText = '-'
        li.appendChild(a)
        this.value = '';
        count()
    }
}
// 获取已经完成的ul
var donelist = document.querySelector('#donelist');
click(todolist, donelist)
click(donelist, todolist)
function click(ele, targetNode){
    ele.onclick = function(){
        var e = window.event;
        var target = e.target || e.srcElemenet;
        if(target.tagName === 'INPUT' && target.getAttribute('type') === 'checkbox'){
            targetNode.appendChild(target.parentElement)
            count()
        }else if(target.tagName === 'P'){
            var str = '<input type="text" value="'+target.innerText+'">'
            target.innerHTML = str;
            target.firstElementChild.onblur = function(){
                target.innerText = this.value;
            }
        }else if(target.tagName === 'A'){
            
                target.parentElement.parentElement.removeChild(target.parentElement)
                count()
        }
    }
}
// 统计次数
function count(){
    document.querySelector('#todocount').innerText = todolist.children.length
    document.querySelector('#donecount').innerText = donelist.children.length
}
// ip 地址获取渲染
const ip = document.querySelector('#ipv4')
const area = document.querySelector('#addr')
zn()
async function zn(){
 const res =await pAjax({
    url:"/dt",
    dataType:'json'
})
console.log(res);
ip.innerText = res.beginip
area.innerText = res.area
}
